package com.xlh.enums.user;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Objects;

/**
 * 日志事件码制
 * <p>
 * Created by lx on 2019/1/28.
 */
@Getter
@AllArgsConstructor
public enum EventCodeEnum {

    LOGIN("10001", "登陆"),
    LOGOUT("10002", "退出"),
    CHAPTER_RECORDING("10003", "章节学习记录"),
    CHAPTER_STUDIED("10004", "章节已学完记录");

    private String code;

    private String message;

    public static EventCodeEnum getByCode(String code) {
        for (EventCodeEnum eventCodeEnum : EventCodeEnum.values()) {
            if (Objects.equals(eventCodeEnum.getCode(), code)) {
                return eventCodeEnum;
            }
        }
        return null;
    }

    public static String getMessageByCode(String code) {
        EventCodeEnum eventCodeEnum = getByCode(code);
        return eventCodeEnum == null ? null : eventCodeEnum.getMessage();
    }

}
